package com.miao.vo;

import com.miao.constant.ResultStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.ibatis.annotations.Results;

/**
 * @author: 丰
 * @date: 2023/3/1 13:50
 */
@Data
@AllArgsConstructor
public class ResultVo<T> {

    private String msg;
    private Integer code;
    private T data;

    public static <T> ResultVo<T> success(T data){
        return new ResultVo<T>(ResultStatusEnum.SUCCESS.getMsg(), ResultStatusEnum.SUCCESS.getCode(), data);
    }
    public static <T> ResultVo<T> failed() {
        return new ResultVo<T>(ResultStatusEnum.FAILED.getMsg(), ResultStatusEnum.FAILED.getCode(), null);
    }
    public static <T> ResultVo<T> failed(T data) {
        return new ResultVo<T>(ResultStatusEnum.FAILED.getMsg(), ResultStatusEnum.FAILED.getCode(), data);
    }
    public ResultVo<T> msg(String msg){
        this.setMsg(msg);
        return this;
    }
    public ResultVo<T> code(Integer code){
        this.setCode(code);
        return this;
    }
    public ResultVo<T> data(T data){
        this.setData(data);
        return this;
    }
}
